package com.zyy.smartcity1129.me;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.LoginActivity;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.UserInfo;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.XCUtli;

public class  MeFragment extends BaseFragment {
    private ImageView imgMeUser;
    private LinearLayout lineMe1;
    private LinearLayout lineMe2;
    private LinearLayout lineMe3;
    private LinearLayout lineMe4;
    private LinearLayout lineMe5;
    private Button btnMeQuit;
    public static UserInfo.UserBean userBean;

    @Override
    protected int layId() {
        return R.layout.f_me;
    }

    @Override
    protected String title() {
        return "个人中心";
    }

    @Override
    protected boolean back() {
        return false;
    }

    @Override
    protected Boolean bottom() {
        return true;

    }

    @Override
    protected void init(View iv) {
        initView(iv);
        XCUtli xcUtli = new XCUtli(1);
        xcUtli.then(() -> {
            userBean = Http.getInstance().get("/prod-api/api/common/user/getInfo", null, UserInfo.class, 1).getUser();
            xcUtli.addint();
        });
        xcUtli.XCliveData.observe(getViewLifecycleOwner(), a -> {
            if (a.get() == 1) {
                Glide.with(imgMeUser.getContext()).load(userBean.getAvatar()).into(imgMeUser);
                if (!userBean.getAvatar().equals("")) {
                    Log.i("TAG1", Http.base + userBean.getAvatar());
                    Glide.with(imgMeUser.getContext()).load(userBean.getAvatar()).into(imgMeUser);
                }
            }
        });
        lineMe1.setOnClickListener(view -> {
            add(new MyAccountFragment());
        });
        lineMe2.setOnClickListener(view -> {
            add(new MyDataFragment());
        });
        lineMe3.setOnClickListener(view -> {
            add(new MyOrderFragment());
        });
        lineMe4.setOnClickListener(view -> {
            add(new ChangePwdFragment());
        });
        lineMe5.setOnClickListener(view -> {
            add(new MyFeedbackFragment());
        });
        btnMeQuit.setOnClickListener(view -> {
            startActivity(new Intent(getContext(), LoginActivity.class));
            getActivity().finish();
        });
    }

    private void initView(View iv) {
        imgMeUser = (ImageView) iv.findViewById(R.id.imgMeUser);
        lineMe1 = (LinearLayout) iv.findViewById(R.id.lineMe1);
        lineMe2 = (LinearLayout) iv.findViewById(R.id.lineMe2);
        lineMe3 = (LinearLayout) iv.findViewById(R.id.lineMe3);
        lineMe4 = (LinearLayout) iv.findViewById(R.id.lineMe4);
        lineMe5 = (LinearLayout) iv.findViewById(R.id.lineMe5);
        btnMeQuit = (Button) iv.findViewById(R.id.btnMeQuit);
    }
}
